package br.com.sovi.resources.empresa;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.codehaus.jettison.json.JSONException;
import org.openinsula.vulcano.core.command.invoker.CommandInvoker;
import org.openinsula.vulcano.orm.command.factory.CommandFactory;
import org.openinsula.vulcano.orm.dao.query.builder.DaoSelect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import br.com.sovi.persistence.Empresa;
import br.com.sovi.resources.Constants;

@Component
@Path("/empresa")
@Produces(Constants.MEDIA_TYPE_PRODUCES)
public class EmpresaResource {

	private final Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private CommandInvoker commandInvoker;

	@GET
	@Path("/all")
	public List<EmpresaVO> getAll() throws JSONException {
		logger.debug("Buscando todas as empresas.");

		List<Empresa> invoke = commandInvoker.invoke(CommandFactory.newFind(new DaoSelect<Empresa>().all().from(
				Empresa.class).toQuery()));

		return EmpresaVO.converList(invoke);
	}

}
